<template>
  <div class="child">
    <h3>子组件2(弟弟)</h3>
    <h4>电脑:{{ computer }}</h4>
    <h4 v-show="toy">哥哥给的玩具:{{ toy }}</h4>
  </div>
</template>

<script setup lang="ts">
import { ref, onUnmounted } from "vue";
import emitter from "../../utils/emitter";
let computer = ref("神威·太湖之光");
let toy = ref("");
emitter.on("send-toy", (value: any) => {
  //给emitter绑定send-toy事件
  console.log("send-toy");
  toy.value = value;
});

onUnmounted(() => {
  emitter.off("send-toy");
});
</script>

<style scoped>
.child {
  background: rgb(231, 190, 112);
  padding: 10px;
  box-shadow: 0 0 10px black;
  border-radius: 10px;
}
</style>
